package hadoop.mapreduce.partition;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;


public class PhoneReducer extends Reducer <Text,PhoneBean,Text,Text>{
    // key         values
    //{13736230513,{phoneBean{2481,24681,27162},phoneBean{2481,24681,27162}}}

    @Override
    protected void reduce(Text key, Iterable<PhoneBean> values, Context context) throws IOException, InterruptedException {
        PhoneBean phoneBean = new PhoneBean();
        long upFlow = 0;
        long downFlow = 0;
        long sumFlow = 0;
        for (PhoneBean value : values) {
            upFlow+=value.getUpFlow();
            downFlow+=value.getDownFlow();
            sumFlow+=value.getSumFlow();
        }
        phoneBean.setUpFlow(upFlow);
        phoneBean.setDownFlow(downFlow);
        phoneBean.setSumFlow(sumFlow);

        context.write(key,new Text(phoneBean.toString()));
    }
}
